package www.openteam.com.model.PrdctnMngmnt;

import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;
import www.openteam.com.base.BaseModel;
import www.openteam.com.bean.MaxRdsno;
import www.openteam.com.bean.StockTaxLocation;
import www.openteam.com.bean.StockTaxMaterial;
import www.openteam.com.bean.UpdateInfo;

/**
 * Created by Administrator on 2019-12-23.
 */

public class StockTaxModel extends BaseModel {

    public interface DataFromClassCodeListener {

        void success(StockTaxMaterial stockTaxMaterial);

        void fail(String msg);
    }

    public interface LocationListener {

        void success(StockTaxLocation stockTaxLocation);

        void fail(String msg);
    }

    public interface MaxRdsnoListener {

        void success(MaxRdsno maxRdsno);

        void fail(String msg);
    }

    public interface InsertStCheckListener {

        void success(UpdateInfo info);

        void fail(String msg);
    }

    public void getDataFromClassCode(String code,String lcode, final DataFromClassCodeListener listener){
        httpApiService.findDataFromCode(code,lcode).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<StockTaxMaterial>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        listener.fail(e.getMessage());
                    }

                    @Override
                    public void onNext(StockTaxMaterial stockTaxMaterial) {
                        listener.success(stockTaxMaterial);
                    }
                })
        ;
    }

    public void findLocation(final LocationListener listener){
        httpApiService.findLocation().subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<StockTaxLocation>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        listener.fail(e.getMessage());
                    }

                    @Override
                    public void onNext(StockTaxLocation stockTaxLocation) {
                        listener.success(stockTaxLocation);
                    }
                })
        ;
    }

    public void findMaxRdsno(String tablename,String morecom,String prefix,String link,String year,String month,
                             final MaxRdsnoListener listener){
        httpApiService.findMaxRdsno(tablename,morecom,prefix,link,year,month).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<MaxRdsno>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        listener.fail(e.getMessage());
                    }

                    @Override
                    public void onNext(MaxRdsno maxRdsno) {
                        listener.success(maxRdsno);
                    }
                })
        ;
    }

    public void insertStCheck(String group,String inputer,String morecom,String mId,String inputDate,
                             final InsertStCheckListener listener){
        httpApiService.insertStCheckStock(group,inputer,morecom,mId,inputDate).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<UpdateInfo>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        listener.fail(e.getMessage());
                    }

                    @Override
                    public void onNext(UpdateInfo info) {
                        listener.success(info);
                    }
                })
        ;
    }
}
